package com.java2207.group1.controller;


import com.java2207.group1.common.LayuiPageVo;
import com.java2207.group1.common.R;
import com.java2207.group1.pojo.Site;
import com.java2207.group1.service.SiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/site")
public class SiteController {

    @Autowired
    private SiteService siteService;

    // 查询、分页
    @RequestMapping("/siteList")
    public LayuiPageVo<Site> sitePageData(@RequestParam Map<String, Object> params){
        return siteService.sitePageData(params);
    }

    // 添加文娱场地信息
    @RequestMapping("/addSite")
    public R addSite(Site site){
        int i = siteService.addSite(site);

        if (i == 1){
            return R.ok();
        }else {
            return R.error();
        }
    }

    // 根据 id 删除文娱场地信息
    @RequestMapping("/deleteSite")
    public R deleteSite(int id){
        System.out.println(id);

        int i = siteService.deleteSite(id);
        if (i == 1){
            return R.ok();
        }else {
            return R.error();
        }
    }

    // 修改文娱场地信息
    @RequestMapping("/updateSite")
    public R updateSite(Site site){
        int i = siteService.updateSite(site);
        if (i == 1){
            return R.ok();
        }else {
            return R.error();
        }
    }

    // 批量删除
    @GetMapping("/batchSite")
    public R batchSite(String ids){
        int i = siteService.batchSite(ids);

        if (i > 0){
            return R.ok();
        }else {
            return R.error();
        }
    }

}
